﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CodeBuilderForVisualStudio.Entity
{
    /// <summary>
    /// 用于读取customSetting.json
    /// </summary>
    public class ConfigHelper
    {
        /// <summary>
        /// 获取自定义设置项
        /// </summary>
        /// <returns></returns>
        public static AppSetting GetAppSetting(string apiDir)
        {
            string path = Path.Combine(apiDir, "appsettings.json");
            return Newtonsoft.Json.JsonConvert.DeserializeObject<AppSetting>(File.ReadAllText(path));
        }

        /// <summary>
        /// 是否为我的框架
        /// </summary>
        /// <returns></returns>
        public static bool IsFlyadminApi(string apiDir)
        {
            try
            {
                GetAppSetting(apiDir);
                return true;
            }
            catch
            {
                return false;
            }
        }

        /// <summary>
        /// 是否为数据表的实体类
        /// </summary>
        /// <param name="apiDir">api路径，读取配置文件用</param>
        /// <param name="nameSpace">当前选择的命名空间</param>
        /// <returns></returns>
        public static bool IsDataTable(string apiDir, string nameSpace)
        {
            try
            {
                AppSetting appSetting = GetAppSetting(apiDir);

                return appSetting.DataTableNameSpace == nameSpace;
            }
            catch
            {
                return false;
            }
        }
    }
}
